﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Threading.Tasks;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace NTmdb.TestProject
{
    /// <summary>
    ///     This is a test class for TmdbTranslationsTest and is intended
    ///     to contain all TmdbTranslationsTest Unit Tests
    /// </summary>
    [TestClass]
    public class TmdbTranslationsTest
    {
        /// <summary>
        ///     A test for TmdbTranslations Constructor
        /// </summary>
        [TestMethod]
        public void TmdbTranslationsConstructorTest()
        {
            var target = new TmdbTranslations();
            Assert.IsNotNull( target );
        }

        /// <summary>
        ///     A test for Id
        /// </summary>
        [TestMethod]
        public void IdTest()
        {
            var target = new TmdbTranslations();
            int expected = new Random().Next( 0, Int32.MaxValue );
            int actual;
            target.Id = expected;
            actual = target.Id;
            Assert.AreEqual( expected, actual );
        }

        /// <summary>
        ///     A test for Translations
        /// </summary>
        [TestMethod]
        public void TranslationsTest()
        {
            var target = new TmdbTranslations();
            var expected = new List<TmdbTranslation>();
            List<TmdbTranslation> actual;
            target.Translations = expected;
            actual = target.Translations;
            Assert.AreSame( expected, actual );
        }

        /// <summary>
        ///     A test for Serialize & Deserialize
        /// </summary>
        [TestMethod]
        [DeploymentItem(@"..\..\TestData\translations.json.txt")]
        public async Task SerializeDeserializeTest()
        {
            var target = new TmdbTranslations();
            var jsonContent = File.ReadAllText("translations.json.txt");
            var actual = await target.DeserializeJson<TmdbTranslations>(jsonContent);

            Assert.AreEqual( 550, actual.Id );
            Assert.AreEqual(3, actual.Translations.Count);
            Assert.AreEqual("en", actual.Translations[0].Iso639_1);
            Assert.AreEqual("English", actual.Translations[0].Name);
            Assert.AreEqual("English", actual.Translations[0].EnglishName);

            Assert.AreEqual("pt", actual.Translations[1].Iso639_1);
            Assert.AreEqual("Portugu�s", actual.Translations[1].Name); //sorry had no time to mess around with the text encoding...
            Assert.AreEqual("Portuguese", actual.Translations[1].EnglishName);

            Assert.AreEqual("tr", actual.Translations[2].Iso639_1);
            Assert.AreEqual("T�rk�e", actual.Translations[2].Name);
            Assert.AreEqual("Turkish", actual.Translations[2].EnglishName);
        }
    }
}